<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/include/page.jsp"%>
<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<title>邮件列表 - 邮件威胁检测</title>
		<%@ include file="/common/include/title_back.jsp" %>
	</head>
	<body>
		<nav class="breadcrumb">
			<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
			邮件管理 <span class="c-gray en">&gt;</span> 邮件列表 <a
				class="btn btn-success radius r"
				style="line-height: 1.6em; margin-top: 3px"
				href="javascript:location.replace(location.href);" title="刷新"><i
				class="Hui-iconfont">&#xe68f;</i></a>
		</nav>
		<div class="page-container">
			<form action="${rootPath }/back/EmailBackServlet?method=emailList" method="post">
				<div class="text-c">
					<input type="text" class="input-text" style="width: 250px" placeholder="输入关键字" 
					id="" name="keyword" value="${requestScope.keyword }">
					状态:
					<select name="status">
						<option value="" ${requestScope.status == '' ? 'selected' : ''}>请选择</option>
						<option value="1"  ${requestScope.status == '1' ? 'selected' : ''}>启用</option>
						<option value="0" ${requestScope.status == '0' ? 'selected' : ''}>禁用</option>
					</select>
					日期范围：
					<input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" 
					id="datemin" name="st" readonly="readonly" class="input-text" 
					 value="${requestScope.st }"
					style="width: 150px;">
					- 
					<input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" 
					id="datemax" name="ed" readonly="readonly" class="input-text" 
					value="${requestScope.ed }"
					style="width: 150px;">
					<button type="submit" class="btn btn-success" id="" name="">
						<i class="Hui-iconfont">&#xe665;</i> 搜索
					</button>
				</div>
			</form>
			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<!-- <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
						<i class="Hui-iconfont">&#xe6e2;</i>
						批量删除
					</a> -->
					<%--
						onclick事件
						参数1:弹出选项卡的标题,
						参数2:url
						参数3:宽度
						参数4:高度
					 --%>
					<a href="javascript:;" onclick="admin_add('添加邮件','${rootPath}/back/EmailBackServlet?method=emailInsert','800','500')"
						class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i>
						添加邮件
					</a>
				</span>
				<span class="r">共有数据：<strong>${requestScope.pageInfoUtil.totalRecord }</strong> 条
				</span>
			</div>
			<div class="text-c">
				批量操作类型:
				<span class="select-box inline">
					<select name="operType" class="select" id="operType" onchange="batchSwitch('operType')">
						<option value="resultInsert">批量验证</option>
						<option value="all">全部验证</option>
					</select>
				</span>
				<a href="javascript:;" onclick="return batchOper('ids','${rootPath }/back/EmailBackServlet','method=emailBatch&operType=' + $('#operType').val())"
					class="btn btn-danger radius">
					<i class="Hui-iconfont">&#xe6e2;</i>
					提交
				</a>
			</div>
			<div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
				<table class="table table-border table-bordered table-bg">
					<thead>
						<tr>
							<th scope="col" colspan="12">邮件列表</th>
						</tr>
						<tr class="text-c">
							<th width="25"><input type="checkbox" name="" value="" id="selectAll" onclick="return checkAll('selectAll','ids')"></th>
							<th width="40">ID</th>
							<th width="140">编号</th>
							<th width="80">收件人</th>
							<th width="90">发件人</th>
							<th width="110" title="ip国家">ip</th>
							<th width="110">登录ip</th>
							<th width="140" title="发信人名称">名称</th>
							<th width="80">状态</th>
							<th width="150">发送时间</th>
							<th width="150">入库时间</th>
							<th width="50">操作</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${requestScope.list }" var="email" varStatus="stat">
							<tr class="text-c">
								<td><input type="checkbox" value="${email.id }" name="ids"></td>
								<td>${email.id }</td>
								<td title="${email.tag }">${fn:substring(email.tag,0,strLen)}</td>
								<td title="${email.rcpt }">${fn:substring(email.rcpt,0,strLen)}</td>
								<td title="${email.sender }">${fn:substring(email.sender,0,strLen)}</td>
								<td title="${email.region }">${fn:substring(email.region,0,strLen)}</td>
								<td>${email.ip }</td>
								<td title="${email.fromname }">${fn:substring(email.fromname,0,strLen)}</td>
								<td class="td-status">
									<span class="label label-success radius">
										${email.statusStr}
									</span>
								</td>
								<td><fmt:formatDate value="${email.sendTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								<td><fmt:formatDate value="${email.createTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								<td class="td-manage">
									<a title="查看" href="javascript:;" onclick="admin_edit('邮件查看','${rootPath}/back/EmailBackServlet?method=emailUpdate&operType=emailInfo&id=${email.id }','admins_view_${email.id }','800','500')"
										class="ml-5" style="text-decoration: none">
										<i class="Hui-iconfont">&#xe631;</i>
									</a>
									<a title="编辑" href="javascript:;" onclick="admin_edit('邮件编辑','${rootPath}/back/EmailBackServlet?method=emailUpdate&operType=emailUpdate&id=${email.id }','admins_edit_${email.id }','800','500')"
										class="ml-5" style="text-decoration: none">
										<i class="Hui-iconfont">&#xe6df;</i>
									</a>
								</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				
				<form action="${rootPath }/back/EmailBackServlet?method=emailList" id="pageForm" method="post">
					<!-- 在每次提交的时候,将搜索条件放到表单中
						hidden:隐藏域,不会在页面上显示
					 -->
					<input type="hidden" name="keyword" value="${requestScope.keyword }">
					<input type="hidden" name="status" value="${requestScope.status }">
					<input type="hidden" name="st" value="${requestScope.st }">
					<input type="hidden" name="ed" value="${requestScope.ed }">
				
					<div class="dataTables_info" id="DataTables_Table_0_info" role="status" aria-live="polite">
						共 ${requestScope.pageInfoUtil.totalRecord } 条,
						共${requestScope.pageInfoUtil.totalPage }页 
					</div>
					<div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
						<a class="paginate_button previous"
							aria-controls="DataTables_Table_0" data-dt-idx="0" tabindex="0"
							href="#"
							onclick="return pageFormSubmit('pageForm','currentPage','1','pageSize','${requestScope.pageInfoUtil.pageSize }')"
							id="DataTables_Table_0_previous">首页
						</a>
						<a class="paginate_button previous"
							aria-controls="DataTables_Table_0" data-dt-idx="0" tabindex="0"
							onclick="return pageFormSubmit('pageForm','currentPage','${requestScope.pageInfoUtil.prePage }','pageSize','${requestScope.pageInfoUtil.pageSize }')"
							id="DataTables_Table_0_previous">上一页
						</a>
						<!-- <span>
							<a class="paginate_button current" aria-controls="DataTables_Table_0"
							data-dt-idx="1" tabindex="0">
							1
							</a>
						</span> -->
						<a class="paginate_button next"
							aria-controls="DataTables_Table_0" data-dt-idx="2" tabindex="0"
							onclick="return pageFormSubmit('pageForm','currentPage','${requestScope.pageInfoUtil.nextPage }','pageSize','${requestScope.pageInfoUtil.pageSize }')"
							id="DataTables_Table_0_next">
							下一页
						</a>
						<a class="paginate_button previous"
							aria-controls="DataTables_Table_0" data-dt-idx="0" tabindex="0"
							onclick="return pageFormSubmit('pageForm','currentPage','${requestScope.pageInfoUtil.totalPage }','pageSize','${requestScope.pageInfoUtil.pageSize }')"
							id="DataTables_Table_0_previous">尾页
						</a>
						第<input type="text" id="currentPage" name="currentPage" value="${requestScope.pageInfoUtil.currentPage }" size="5" maxlength="5" class="paginate_button">页
						每页<input type="text" id="pageSize" name="pageSize" value="${requestScope.pageInfoUtil.pageSize }" size="5" maxlength="5" class="paginate_button">条
						<input type="submit" value="GO" class="paginate_button">
					</div>
				</form>
			</div>
		</div>
		
		<%@ include file="/common/include/footer_back.jsp"%>
	</body>
</html>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${rootPath}/common/resource/H-ui.admin/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="${rootPath}/common/resource/H-ui.admin/lib/datatables/1.10.15/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="${rootPath}/common/resource/H-ui.admin/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
	/*
		参数解释：
		title	标题
		url		请求的url
		id		需要操作的数据id
		w		弹出层宽度（缺省调默认值）
		h		弹出层高度（缺省调默认值）
	*/
	/*管理员-增加*/
	function admin_add(title,url,w,h){
		layer_show(title,url,w,h);
	}
	/*管理员-删除*/
	function admin_del(obj,id){
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				type: 'POST',
				url: '',
				dataType: 'json',
				success: function(data){
					$(obj).parents("tr").remove();
					layer.msg('已删除!',{icon:1,time:1000});
				},
				error:function(data) {
					console.log(data.msg);
				},
			});		
		});
	}
	
	/*管理员-编辑*/
	function admin_edit(title,url,id,w,h){
		layer_show(title,url,w,h);
	}
	/*管理员-停用*/
	function admin_stop(obj,id){
		layer.confirm('确认要停用吗？',function(index){
			//此处请求后台程序，下方是成功后的前台处理……
			
			$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this,id)" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
			$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
			$(obj).remove();
			layer.msg('已停用!',{icon: 5,time:1000});
		});
	}
	
	/*管理员-启用*/
	function admin_start(obj,id){
		layer.confirm('确认要启用吗？',function(index){
			//此处请求后台程序，下方是成功后的前台处理……
			
			
			$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,id)" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
			$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
			$(obj).remove();
			layer.msg('已启用!', {icon: 6,time:1000});
		});
	}
	
	/**
		批量操作
	*/
	function batchOper(tarids,requestUrl,operType)
	{
		/* 检查复选框是否选择 */
		var flag = checkOneSubmit(tarids);
		if(!flag)
		{
			return false ; 
		}
		/* alert($("input[name="+ tarids +"]").length) */
		var chsStr = operType +"&";
		var chs = $("input[name=" + tarids + "]")
		chs.each(function()
		{
			if ($(this).prop("checked"))
			{
				chsStr = chsStr + $(this).attr("name") + "="
						+ $(this).attr("value") + "&";
			}
		});
		//alert("===>" + chsStr)
		/* 可以提交 */
		$.post(requestUrl, chsStr, function(data)
		{
			/* 页面的提示 */
			layer.msg(data.info,
			{
				icon : 1,
				time : 5000
			},
					function()
					{
						/* 主线程等待 */
						/* 弹出的选项卡是否关闭的问题 */
						/* 如果添加成功的时候关闭或者关闭 */
						if (data.code == '0')
						{
							var index = parent.layer
									.getFrameIndex(window.name);
							parent.$('.btn-refresh').click();
							parent.layer.close(index);
						}
					});
		}, "json");
		return false ; 
	}
</script>